package com.legoo.studaychineseonline.activity;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;


import com.legoo.studaychineseonline.R;
import com.legoo.studaychineseonline.base.BaseActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 作者：Administrator on 2019/3/7 0007 18:14
 * <p>
 * When I wrote this, only God and I understood what I was doing
 * Now, only God knows
 */
public class WebActivity extends BaseActivity {
    @BindView(R.id.tv_title_left)
    TextView tvBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_title_right)
    TextView tvTitleRight;
    @BindView(R.id.web)
    WebView web;
    private String url;
    private String  status = "0";
    @Override
    protected void myOnCreate(@Nullable Bundle savedInstanceState) {
        ButterKnife.bind(this);
    }

    @Override
    protected void initData() {
        Intent intent = getIntent();
        tvTitleRight.setBackgroundResource(0);
        tvBack.setBackgroundResource(R.mipmap.img_fanhui);
        url = intent.getStringExtra("url");
        web.getSettings().setJavaScriptEnabled(true);
        tvTitle.setText(intent.getStringExtra("title"));
        web.getSettings().setUseWideViewPort(true);
        web.getSettings().setLoadWithOverviewMode(true);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            web.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        }
//        webView.getSettings().setDomStorageEnabled(true);
//        webView.getSettings().setBlockNetworkImage(true);
        showProgressDialog();

        switch (intent.getStringExtra("status")){
            case "0":
                web.loadUrl(url);
                web.setWebViewClient(new HelloWebViewClient());
                break;
        }
    }

    @Override
    protected void resolveBundle(Bundle bundle) {

    }

    @Override
    protected int myLayoutId() {
        return R.layout.activity_web;
    }



    @OnClick({R.id.tv_title_left, R.id.web})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_title_left:
                finish();
                break;

        }
    }

    private class HelloWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            view.loadUrl(url);
            return true;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            hideProgressDialog();
            super.onPageFinished(view, url);
//            webView.getSettings().setBlockNetworkImage(false);
        }

    }
}
